import React, { Component } from 'react'
import { nanoid } from 'nanoid';
import './index.css'
export default class Header extends Component {
    //回车输出事件
    onKeyUpBtn = (event) => {
        const { keyCode, target } = event;
        if (keyCode !== 13) return;
        if (target.value === "") {
            return alert('给我填上！！！');
        }
        const todoObj = { id: nanoid(), name: target.value, falg: false };
        this.props.addTodo(todoObj);
        target.value = '';
    }
    render() {
        return (
            <div className="todo-header">
                <input type="text" onKeyUp={this.onKeyUpBtn} placeholder="请输入你的任务名称，按回车键确认" />
            </div>
        )
    }
}
